﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using Chefbook.DataObjects;
using NUnit.Framework;
using Rhino.Mocks;
using Chefbook.DataAccessLayer;
using Chefbook.UserActions;

namespace UnitTests.UserActionsTests
{
    [TestFixture]
    public class DeleteRecipeActionFixture
    {
        private MockRepository mocks;
        private IUserAction action;
        private Category category1, category2;
        private Recipe recipe;
        private ChefbookEntities db;

        [SetUp]
        public void Init()
        {
            mocks = new MockRepository();
            db = new ChefbookEntities();

            category1 = new Category();
            category2 = new Category();
            recipe = new Recipe();
            category2.AddRecipe(recipe);

            Assert.True(recipe.Categories.Contains(category2));
            Assert.Contains(recipe, category1.DirectRecipes);
            Assert.Contains(category2, recipe.Categories);
            Assert.Contains(recipe, category2.DirectRecipes);

            action = new DeleteRecipeAction(recipe) { DatabaseConnector = db };
        }

        [Test]
        public void DoActionTest()
        {
            action.DoAction();
            Assert.False(recipe.Categories.Contains(category1), "recipe.Categories.Contains(category1)");
            Assert.False(category1.DirectRecipes.Contains(recipe), "category1.DirectRecipes.Contains(recipe)");
            Assert.False(recipe.Categories.Contains(category2), "recipe.Categories.Contains(category2)");
            Assert.False(category2.DirectRecipes.Contains(recipe), "category2.DirectRecipes.Contains(recipe)");
            
        }

        [Test]
        public void UndoActionTest()
        {
            action.DoAction();
            action.UndoAction();
            Assert.Contains(category1, recipe.Categories);
            Assert.Contains(recipe, category1.DirectRecipes);
            Assert.Contains(category2, recipe.Categories);
            Assert.Contains(recipe, category2.DirectRecipes);
        }

        [Test]
        public void UndoActionWithoutDoingTest()
        {
            UserActionTestsHelper.UndoActionWithoutDoingTest(action);
        }

        [Test]
        public void UndoActionTwiceAfterDoingTest()
        {
            UserActionTestsHelper.UndoActionTwiceAfterDoingTest(action);
        }

        [Test]
        public void DoActionTwiceTest()
        {
            UserActionTestsHelper.DoActionTwiceTest(action);
        }
        [Test]
        public void ActionNameTest()
        {
            Assert.AreEqual(string.Format("Delete Recipe '{0}'", recipe), action.ToString());
        }
    }
}
